package desgin.pattern.other.reactor;

import java.nio.channels.ClosedChannelException;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.SocketChannel;

/**
 * Created by kai on 2015/6/28 0028.
 */
public class NioConnection {
    private final SocketChannel socketChannel;
    private SelectionKey selectionKey;

    public NioConnection(SocketChannel socketChannel) {
        this.socketChannel = socketChannel;
    }

    public void register(Selector selector) throws ClosedChannelException {
        selectionKey = socketChannel.register(selector, SelectionKey.OP_READ, this);
        System.out.println(selector.selectedKeys());
        System.out.println("registed complete ...");
    }

    public void write() {
        System.out.println("write complete...");
    }

    public void read() {
        System.out.println("read complete...");
    }

    public SocketChannel getSocketChannel() {
        return socketChannel;
    }

    public SelectionKey getSelectionKey() {
        return selectionKey;
    }

    public void setSelectionKey(SelectionKey selectionKey) {
        this.selectionKey = selectionKey;
    }
}
